const userModel = require('../models/user.model');
const cache = require('../../lib/cache.lib');
const _ = require('lodash');

/**
 * 用户service
 */
class UserService {
    constructor() { }
    async login({ name, password, token, captcha } = data) {
        let code = cache.get(token);
        if (_.isUndefined(code)) {
            return "验证码已过期";
        }
        if (code !== String(captcha).toUpperCase()) {
            cache.del(token)
            return "验证码有误";
        }
        let result = await userModel.queryUserObject({ login_name: name, password });
        if (_.isNull(result)) {
            return "用户名或密码有误";
        }
        return true;
    }
}


module.exports = global.buildClass(UserService);